<template>
	<div class="container">
		<!-- 路径导航区域 -->
				<el-breadcrumb separator="/">
					<el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
					<el-breadcrumb-item>咨询回复管理</el-breadcrumb-item>
				</el-breadcrumb>
				<!-- 搜索区域 -->
				<el-row>
					<el-form :inline="true">
						<el-form-item label="咨询类型">
							<el-input v-model="queryInfo.appointmentConsultation" @clear="queryList" placeholder="请输
		入咨询类型" clearable></el-input>
						</el-form-item>
						<el-form-item>
							<el-button type="primary" @click="queryList">搜索</el-button>
							<el-button type="danger">批量删除</el-button>
						</el-form-item>
					</el-form>
				</el-row>
		<!-- 表格区域 -->
		<el-table :data="appointmentList" border style="width: 100%"
		:cell-style="{'text-align':'center'}"
					:header-cell-style="{'text-align':'center',fontSize:'14px'}">
			<el-table-column type="selection" width="55"></el-table-column>
			<el-table-column prop="appointmentId" label="ID"></el-table-column>
			<el-table-column prop="consult.consultName" label="咨询师">
			</el-table-column>
			<el-table-column prop="appointmentConsultation" label="咨询类型">
			</el-table-column>
			<el-table-column prop="appointmentTime" label="咨询时间">
			</el-table-column>
			<el-table-column prop="appointmentContent" label="咨询内容">
			</el-table-column>
			<el-table-column prop="appointmentResponse" label="回复内容">
			</el-table-column>
			<el-table-column prop="appointmentStatus" label="状态" align="center">
				<template slot-scope="scope">
					<el-button size="mini" type="danger" plain disabled
						v-show="scope.row.appointmentStatus==0? true:false">未完成</el-button>
					<el-button size="mini" type="success" plain disabled
						v-show="scope.row.appointmentStatus==1? true:false">已回复</el-button>
					<el-button size="mini" type="danger" plain disabled
						v-show="scope.row.appointmentStatus==2 ? true:false">未评价</el-button>
					<el-button size="mini" type="success" plain disabled
						v-show="scope.row.appointmentStatus==3 ? true:false">已评价</el-button>
				</template>
			</el-table-column>
			<el-table-column label="操作">
				<template slot-scope='scope'>
					<el-link type="primary" @click="toEditAppointment(scope.row)">回复</el-link>
					<el-link type="primary" @click="toDeleteAppointment(scope.row.appointmentId)">删除</el-link>
				</template>
			</el-table-column>
		</el-table>
		<!-- 分页区域 -->
		<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
			:current-page="queryInfo.pageNum" :page-sizes="[1, 5, 10, 20]" :page-size="queryInfo.pageSize"
			layout="total, sizes, prev, pager, next, jumper" :total="total">
		</el-pagination>
		
		
		<!-- 新增和修改的对话框 -->
		<el-dialog :title="title" :visible.sync="dialogFormVisible" @close="cancle">
			<el-form :model="appointment">
				<el-form-item label="咨询类型" label-width="80px">
				<el-input v-model="appointment.appointmentConsultation" readonly></el-input>
				</el-form-item>
				<el-form-item label="咨询内容" label-width="80px">
				<el-input v-model="appointment.appointmentContent" readonly></el-input>
				</el-form-item>
				<el-form-item label="回复内容" label-width="80px">
				    <el-input 
				        type="textarea" 
				        placeholder="请输入文章详情" 
				        v-model="appointment.appointmentResponse" 
				        rows="4" 
				    ></el-input>
				</el-form-item>
		        
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="cancle">取 消</el-button>
				<el-button type="primary" @click="addappointment">确 定</el-button>
			</div>
		</el-dialog>
		
	</div>
</template>

<script>
	import {url} from '../../util/tool.js'
	export default {
		data() {
			return {
			
				url:'' ,     // 定义一个全局的url
				// 查询信息对象
				queryInfo: {
					appointmentName: '',
					pageNum: 1,
					pageSize: 10
				},
				total: 0,
				appointmentList: [], 
				title:'',
				dialogFormVisible:false,
				appointment: { // 文章对象
						"appointmentId": '',
						"consultId": "",
						"appointmentConsultation": "",
						"appointmentTime": "",
						"appointmentContent": "",
						"appointmentResponse": '',
						"appointmentStatus": 0,
					},
				dialogImageUrl: '', // 预览图片路径
				dialogVisible: false, // 预览图片的对话框
				fileList:[]
			}
		},
		methods: {
			
			cancle(){
				this.appointment = { // 文章对象
						"appointmentId": '',
						"consultId": "",
						"appointmentConsultation": "",
						"appointmentTime": "",
						"appointmentContent": "",
						"appointmentResponse": '',
						"appointmentStatus": 0,
					}
					// 关闭对话框
					this.dialogFormVisible = false;
					// 重新查询
					this.queryList()
					
			},
			//	去删除文章内容
			toDeleteappointment(appointmentId){
				this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
				     confirmButtonText: '确定',
				     cancelButtonText: '取消',
				     type: 'warning'
				  })
				  .then(()=>{
					  this.$http.delete('appointment/'+appointmentId)
					  .then(res=>{
						  if(res.data.status == 200){
							  this.$message.success("删除成功")
							  this.queryList()
						  }else{
							  this.$message.error("删除失败")
						  }
					  })
				  })
				  .catch(()=>{
					  this.$message({
						  type:'info',
						  message:'已取消删除'
					  })
				  })
			},
			
			//	去修改文章内容
			toEditAppointment(row){
				console.log(row.appointmentPicture);
				// 赋值
				this.appointment = row;
				// 设置标题
				this.title = "回复咨询";
				// 开启对话框
				this.dialogFormVisible = true;
			},
			
			//	添加或修改文章内容
			addappointment(){
				if(this.appointment.appointmentId){//	修改	true
					this.$http.put("appointment",this.appointment)
					.then(res=>{
						if(res.data.status == 200){
							this.$message.success("修改成功！")
							// 清空数据
							this.appointment = { // 文章对象
									"appointmentId": '',
									"consultId": "",
									"appointmentConsultation": "",
									"appointmentTime": "",
									"appointmentContent": "",
									"appointmentResponse": '',
									"appointmentStatus": 0
								}
								// 关闭对话框
								this.dialogFormVisible = false;
								// 重新查询
								this.queryList()
						}else{
							this.$message.error("修改失败！")
						}
					})
				}
			},
			
			// 分页查询所有的数据
			queryList(){
				//	调用后端接口
				this.$http.get('appointment/findByPage',{
					params:this.queryInfo
				})
				.then(res=>{
					if(res.data.status == 200){
						console.log(res);
						this.appointmentList = res.data.data.list
						this.total = res.data.data.total
					}
					else{
						
					}
				})
			},
			handleSizeChange(size) {
				// console.log('每页显示数量发生改变');
				this.queryInfo.pageSize = size
				this.queryInfo.pageNum = 1
				this.queryList()
			},
			handleCurrentChange(num) {
				// console.log('页码发生改变');
				this.queryInfo.pageNum = num
				this.queryList()
			}
		},
		mounted(){
			this.queryList();
			// 动态的获取tool.js中的url，并赋值给当前组件的全局url
			this.url=url;
		}
	}
</script>
<style>
	/**设置富文本编辑器的最小高度，注意style中不能使用scoped **/
	.ql-container{
		min-height: 200px;
	}
	.el-breadcrumb {
		margin-bottom: 15px;
		padding: 0 0 15px;
		border-bottom: 1px solid #ddd;
	}

	.el-pagination {
		margin-top: 15px;
	}

	.el-link {
		padding: 0 5px;
	}
</style>